<template>
	<view class="flex_sbc">
		<view></view>
		<view class="flex_fsc">
			<view class="flex_fsc uni-my-16 edit" @click="switchStanding">
				<uni-icons type="person-filled" size="20" color="#00ab64"></uni-icons>
				<view>切换为学员</view>
			</view>
			<navigator url="/pages/my/personal-setting/personal-setting" class="edit" hover-class="none">
				编辑
			</navigator>
		</view>
	</view>
	<view v-if="userInfo.userId" class="flex_fsc">
		<image :src="setting.oss_pub_domain + userInfo.avatar" class="head-img"></image>
		<view>
			<view class="flex_fsc">
				<view class="z-font-40 text-w u-line-1" style="max-width: 300rpx">{{ userInfo.nickName }}</view>
				<!-- <image src="../../static/my/br.png" class="tag"></image> -->
				<view v-if="userInfo.certAudit" class="certification flex_cc uni-orange-bg">
					<view>已认证</view>
					<uni-icons type="right" color="#FFFFFF" size="12"></uni-icons>
				</view>
				<navigator
					url="/pages/my/certificate/certificate"
					hover-class="none"
					v-else
					class="certification uni-color-grey-bg"
				>
					<view class="flex_cc">
						<view>未认证</view>
						<uni-icons type="right" color="#FFFFFF" size="12"></uni-icons>
					</view>
				</navigator>
			</view>
			<view class="desc-text u-line-2">{{ userInfo.introduce }}</view>
		</view>
	</view>
	<view v-else class="flex_fsc">
		<image
			:src="setting.oss_pub_domain + '/app-img/my/default-head.png'"
			style="width: 116rpx; height: 116rpx"
		></image>
		<view class="z-font-40 text-w uni-ml-26">注册/登录{{ userInfo.createTime }}</view>
	</view>
	<view class="my-data flex_fsc">
		<navigator open-type="switchTab" url="/pages/tabbar-page/tabbar-1" class="item">
			<view class="z-font-40 text-w">{{ statisticalData.stuNum }}</view>
			<view class="z-font-24 uni-color-grey">球员数</view>
		</navigator>
		<navigator url="/pages/my/achievement/achievement" class="item" hover-class="none">
			<view class="z-font-40 text-w">{{ statisticalData.achievementNum }}</view>
			<view class="z-font-24 uni-color-grey">我的成就</view>
		</navigator>
		<navigator url="/pages/my/integral/integral" class="item" hover-class="none">
			<view class="z-font-40 text-w">{{ statisticalData.integralNum }}</view>
			<view class="z-font-24 uni-color-grey">我的积分</view>
		</navigator>
		<navigator url="/pages/my/one-to-one/one-to-one" class="item" hover-class="none">
			<view class="z-font-40 text-w">{{ statisticalData.questionNum }}</view>
			<view class="z-font-24 uni-color-grey">1对1答疑</view>
		</navigator>
	</view>
	<view class="common-box function flex_sbc">
		<navigator url="/pages/my/integral/integral" hover-class="none">
			<image :src="setting.oss_pub_domain + '/app-img/my/get.png'"></image>
			<view>赚取积分</view>
		</navigator>
		<navigator url="/pages/my/points-mall/index" hover-class="none">
			<image :src="setting.oss_pub_domain + '/app-img/my/mall.png'"></image>
			<view>积分商城</view>
		</navigator>
		<navigator url="/pages/my/certificate/certificate" hover-class="none">
			<image :src="setting.oss_pub_domain + '/app-img/my/certificate.png'"></image>
			<view>我的证书</view>
		</navigator>
		<!-- <navigator url="/pages/station-message/index" hover-class="none" style="position: relative;">
			<image :src="setting.oss_pub_domain + '/app-img/my/message.png'"></image>
			<view>通知</view>
			<view v-if="prop.noReadCount" class="no-read-number">{{ prop.noReadCount }}</view>
		</navigator> -->
		<navigator url="/pages/my/setting/setting" hover-class="none">
			<image :src="setting.oss_pub_domain + '/app-img/my/setting.png'"></image>
			<view>设置</view>
		</navigator>
	</view>
	<view class="common-box public-class">
		<view class="flex_sbc">
			<view>
				<view class="z-font-32 text-w">我的体系课</view>
				<view class="z-font-22 uni-color-grey uni-mt-4">教练面向学员端发布体系课, 可赚取积分</view>
			</view>
			<view class="create" @click="editOpenCourse()">新建体系课</view>
		</view>
		<view class="line-spacing uni-mt-40"></view>
		<view v-if="openList && openList.length">
			<view v-for="course in openList" :key="course.id" class="item flex_fsc">
				<image :src="setting.oss_pub_domain + course.material" class="class-image" mode="aspectFill"></image>
				<view class="uni-ml-24 width-100">
					<view class="z-font-32">{{ course.name }}</view>
					<view class="z-font-24 uni-color-grey flex_fsc uni-mt-6">
						<view>关联方案:{{ course.relScheme ? course.relScheme.split(',').length - 1 : 0 }}个</view>
						<view class="line"></view>
						<view>兑换:{{ course.tuition || 0 }}积分</view>
					</view>
					<view class="flex_sbc uni-mt-8">
						<view v-if="course.isUp == 2" class="z-font-24 uni-color-main">已上架</view>
						<view v-else class="in-review">{{ openStatusList[course.isUp] }}</view>
						<image
							:src="setting.oss_pub_domain + '/app-img/icon/icon_edit.png'"
							class="icon-size-32"
							@click="editOpenCourse(course)"
						></image>
					</view>
				</view>
			</view>
		</view>
		<z-no-data v-else placeholder="暂无课程包" width="200"></z-no-data>
	</view>
</template>

<script setup>
import { getOpenCourseList } from '@/api/course.js';
import { getUserInfo } from '@/api/user.js';
import { getNumber } from '@/api/my.js';
import { onShow } from '@dcloudio/uni-app';
import { ref, reactive, getCurrentInstance } from 'vue';
const { proxy: that } = getCurrentInstance();

// 体系课
const openList = ref([]);
const openStatusList = ['编辑中', '审核中', '已上架', '驳回'];
function showFun() {
	getOpenList();
	getUserInfo().then((res) => {
		Object.assign(that.userInfo, res);
	});
}

defineExpose({ showFun });
function getOpenList() {
	getOpenCourseList({ pageSize: 10, pageNum: 1 }).then((res) => {
		openList.value = res.rows;
	});
}

//  编辑体系课
function editOpenCourse(item) {
	uni.setStorageSync('open-course', item);
	uni.navigateTo({
		url: '/pages/course/open-course/edit/edit',
		events: {
			editDone: (data) => {
				that.tools.alert('编辑完成');
				that.$forceUpdate();
			}
		}
	});
}

// 获取统计数据
const statisticalData = ref({});
getNumber().then((res) => {
	statisticalData.value = res;
});

function switchStanding() {
	uni.showModal({
		title: '提示',
		content: `是否要切换为学员身份`,
		success: (res) => {
			if (res.cancel) return;
			uni.setStorageSync('start-state', 2);
			uni.reLaunch({
				url: '/pages/tabbar-page/tabbar-0'
			});
		}
	});
}

// 站内消息
const prop = defineProps({
	noReadCount: Number
})
</script>

<style lang="scss">
@import 'index.scss';
.no-read-number {
	position: absolute;
	right: -10rpx;
	top: -10rpx;
	width: 40rpx;
	height: 40rpx;
	text-align: center;
	line-height: 40rpx;
	color: #FFFFFF;
	background-color: #ff4a4a;
	border-radius: 120rpx;
}
</style>
